<?php
  
?>
<form method="post" action="<?php $_SERVER["PHP_SELF"]?>">
<center>
<br/><br/><br/><br/>
 <table>
    <tr>
        <td colspan=3 align=center>
                <h2><p style="color:blue">REGISTER</p></h2>
        </td>
    </tr>
    <tr>
        <td align=top>
           Username:
        </td>
                <td width=20>
        </td>
        <td>
            <input type="text" name="user">     
        </td>
    </tr>
    <tr>
        <td align=top>
           Password:
                      </td>
                <td width=20>
        </td>
        <td>
            <input type="password" name="pass">      
        </td>
    </tr>
    <tr>
        <td align=top>
           Email:
                      </td>
                <td width=20>
        </td>
        <td>
            <input type="email" name="email">      
        </td>
    </tr>
     
        <td colspan=3 align=center>          
            <input type="submit" value="Submit">
        </td>
    </tr>
    <tr>
        <td colspan=3 align=center>          
          <?php 
		  include("Libraries/BusinessLogic/users.php");
		  include("Libraries/BusinessLogic/statheres.php");
		  if(isset($_POST["user"]))
		  { 
		  	$user=$_POST["user"];
    		$pass=$_POST["pass"];
			$email=$_POST["email"]; 
			$result=register_member($user,$pass,$email);
		
			switch ($result['status']) 
			{
			case statheres::USER_EXISTS:
				echo "<script>alert('Username already exists')</script>";
				echo "<noscript><center><h4><font color='red'>Username already exists</p></h4></font></noscript>";
				break;
			case statheres::OLA_OK:
				header('Location: welcome.php');
				break;
			case statheres::EMPTY_FIELD:
				echo "<script>alert('Fill all fields')</script>";
				echo "<noscript><center><h4><font color='red'>Fill all fields</p></h4></font></noscript>";
				break;
			case statheres::LARGE_FIELD:
				echo "<script>alert('Too long fields')</script>";
				echo "<noscript><center><h4><font color='red'>Too long fields</p></h4></font></noscript>";
				break;
			case statheres::EMAIL_EXISTS:
				echo "<script>alert('Email already exists')</script>";
				echo "<noscript><center><h4><font color='red'>Email already exists</p></h4></font></noscript>";
				break;
			default:
				echo "<script>alert('Unexpected error')</script>";
				echo "<noscript><center><h4><font color='red'>Unexpected error</p></h4></font></noscript>";
			}
		  }
		  ?>
        </td>
    </tr>
    <tr>
        <td colspan=3 align=center>          
         
        </td>
    </tr>
</table>
</form>
